package com.cskaoyan.wordmemorize.controller.app;


import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayUserVocSentenceDTO;
import com.cskaoyan.wordmemorize.dto.app.UserFavoriteDTO;
import com.cskaoyan.wordmemorize.dto.app.UserVocBookStatisticsDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserFavoriteCommand;
import com.cskaoyan.wordmemorize.request.UserVocExampleSentenceCommand;
import com.cskaoyan.wordmemorize.service.UserPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/priviledge")
public class AppUserPrivilegeController {

    @Autowired
    UserPrivilegeService userPrivilegeService;

    // APP端添加用户自建例句(√)
    @PostMapping("/voc/example")
    public Result addUserVocSentence(@RequestBody UserVocExampleSentenceCommand command, Long userId){
        userPrivilegeService.addUserVocSentence(command,userId);
        return Result.ok();
    }
    // APP端更新用户自建例句(√)
    @PutMapping("/voc/example")
    public Result updateUserVocSentence(@RequestBody UserVocExampleSentenceCommand command, Long userId){
        userId=StpKit.USER.getLoginIdAsLong();
        userPrivilegeService.updateUserVocSentence(command, userId);
        return Result.ok();
    }
    // APP端删除用户自建例句(√)
    @DeleteMapping("/voc/example/{id}")
    public Result deleteUserVocSentence(@PathVariable Long id){
        userPrivilegeService.deleteUserVocSentence(id);
        return Result.ok();
    }
    // APP端单个添加收藏单词(√)
    @PostMapping("/favorite")
    public Result addFavorite(@RequestBody UserFavoriteCommand userFavoriteCommand, Long userId){
        userPrivilegeService.addFavorite(userFavoriteCommand,userId);
        return Result.ok();
    }
    // APP端批量添加收藏单词(√)
    @PostMapping("/favorite/bulk")
    public Result addFavoriteBulk(@RequestBody List<UserFavoriteCommand> userFavoriteCommand, Long userId){
        userId=StpKit.USER.getLoginIdAsLong();
        userPrivilegeService.addFavoriteBulk(userFavoriteCommand,userId);
        return Result.ok();
    }
      // APP端获取单词收藏列表(√)
    @GetMapping("/favorite/list")
    public Result<PageDTO<UserFavoriteDTO>>  getUserFavoriteList(PageRequest pageRequest, Long userId){
        userId=StpKit.USER.getLoginIdAsLong();
        PageDTO<UserFavoriteDTO> userFavoriteList = userPrivilegeService.getUserFavoriteList(pageRequest, userId);
        return Result.ok(userFavoriteList);
    }
    // APP端取消收藏单词(√)
    @PostMapping("/favorite/cancel")
    public  Result cancelFavorite(@RequestBody List<Long> ids, Long userId){
        userId=StpKit.USER.getLoginIdAsLong();
        userPrivilegeService.cancelFavorite(ids,userId);
        return Result.ok();
    }
    // APP用户标识不想背(√)
    @PostMapping("voc/non")
    public Result notRemember(Long vocId){
        Long userId = StpKit.USER.getLoginIdAsLong();
        userPrivilegeService.notRemember(vocId,userId);
        return Result.ok();
    }

    // APP用户取消不想背(√)
    @PutMapping("voc/non/cancel")
    public Result cancelNotRemember( Long vocId){
        Long userId = StpKit.USER.getLoginIdAsLong();
        userPrivilegeService.cancelNotRemember(vocId,userId);
        return Result.ok();
    }
    // APP端获取用户自建例句(√)
    @GetMapping("voc/example/list")
    public Result getUserVocSentence( PageRequest pageRequest){
        Long userId = StpKit.USER.getLoginIdAsLong();
        PageDTO<DisplayUserVocSentenceDTO> userVocSentence = userPrivilegeService.getUserVocSentence(pageRequest, userId);
        return Result.ok(userVocSentence);
    }
    // APP端获取词书进度
    @GetMapping("current/{bookId}/statistics")
    public Result getBookProgress(@PathVariable("bookId") Long bookId){
        Long userId = StpKit.USER.getLoginIdAsLong();
        UserVocBookStatisticsDTO selectedBookStatistics = userPrivilegeService.getSelectedBookStatistics(userId,bookId);
        return Result.ok(selectedBookStatistics);
    }
}
